var app = getApp()
Page({
  data: {
    url: {
      getCollection: app.url.baseUrl + "/shop/myCollection",
    },
    products: [],
    isPage: true,
    pageNumber: -1,
    shopList : [],
    lat:null,
    lng :null
  },
  onLoad: function () {
   var that = this
    // wx.getLocation({
    //   type: "gcj02",
    //   success: function (res) {
    //     var latitude = res.latitude
    //     var longitude = res.longitude
    //     var speed = res.speed
    //     var accuracy = res.accuracy
    //     that.setData({ lat: latitude, lng: longitude })
    //     that.getCollection()
    //   },
    //   fail:function(){
    //     that.getCollection()
    //   }
    // });
    that.getCollection()
  },
  getCollection: function () {
    if (!this.data.isPage) {
      //提示
      return
    }
    var that = this
    app.ajax(this.data.url.getCollection, { pageNumber: this.data.pageNumber + 1 ,lng :this.data.lng,lat:this.data.lat}, function (res) {
      var d = res.data
      var b = false
      if (d.code == 2000 && d.data.length == 20)
        b = true
      that.setData({ shopList: d.data, isPage: b, pageNumber: that.data.pageNumber += 1 })
    })
  },
  onReachBottom: function () {
    this.getCollection()
  },
  shopInfo: function (e) {
    var shopId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../info/info?id=' + shopId
    })
  },
  refreshData: function () {
    //初始化数据
    this.setData({ pageNumber: -1, shopList: [], isPage: true });
    this.getCollection()
  }
})

